package cc.facesign.admin.task;

import cc.facesign.admin.service.TblConfService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Component
public class ConfTask {

    @Autowired
    private TblConfService confService;

    /**
     * 每5分钟更新一次会议人数(已结束的不做统计)
     */
    @Scheduled(cron = "0 0/5 * * * ?")
    public void updateTotal() {
        log.info("tack:conf: 更新会议总人数");
        List<String> idList = confService.list(null).stream()
                .filter(x -> x.getStatus() != 4)
                .map(x -> x.getId())
                .collect(Collectors.toList());
        for (String id : idList) {
            confService.updateTotal(id);
        }
    }

}
